package com.tanhua.app.service;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.github.tobato.fastdfs.domain.conn.FdfsWebServer;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.tanhua.api.db.UserInfoApi;
import com.tanhua.api.mongo.TaohuaApi;
import com.tanhua.api.mongo.UserLikeApi;
import com.tanhua.api.mongo.VideoApi;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.mogo.FollowUser;
import com.tanhua.domain.mogo.Sound;
import com.tanhua.domain.mogo.Video;
import com.tanhua.domain.vo.PageBeanVo;
import com.tanhua.domain.vo.SoundVo;
import com.tanhua.domain.vo.UserHolder;
import com.tanhua.domain.vo.VideoVo;
import com.tanhua.template.OssTemplate;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/*
-点击接收语音按钮，随机查询一个语音消息返回，
-在听完语音后，可以选择喜欢或者不喜欢
-如果双方互相喜欢那么可以配对成功互相关注。
- 每日的接受数量限制
- 对于语音，只能被一个人获取(细节)

-用户可以选择发送语音，录制一段语音后发出。
*/


@Service
public class TaoHuaService {

    @Reference
    private TaohuaApi taohuaApi;

    @Reference
    private UserLikeApi userLikeApi;

    @Reference
    private UserInfoApi userInfoApi;

    @Autowired
    private OssTemplate ossTempalte;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    //桃花传音语音查询
    public ResponseEntity findSound() {
        System.out.println("桃花传音接收中....");

        //获取用户id
        Long userId = UserHolder.getUser().getId();

        //封装SoundVo数据

        //随机获取一个用户语音  根据userid排除自己的语音
        Sound sound = taohuaApi.findOneSound(userId);
        //获取随机用户的详细信息
        UserInfo userInfo = userInfoApi.findUserInfo(sound.getUserId());
        sound.getId();

        SoundVo soundVo = new SoundVo();

        //封装UserInfo到SoundVo
        BeanUtil.copyProperties(userInfo, soundVo);
        //单独封装userId
        soundVo.setId(userInfo.getId().intValue());
        //封装Sound到SoundVo
        BeanUtil.copyProperties(sound, soundVo);

        return ResponseEntity.ok(soundVo);


    }


    //桃花传音语音发送  oss
    public ResponseEntity sendSound(MultipartFile soundFile) {
        System.out.println("桃花传音发送中....");

        return ResponseEntity.ok(null);
    }


}
